// pages/winRecord/index.js
const Page = require('../../../utils/ald-stat.js').Page;
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    haveMore: '',
    record: '',
    page: 1,
    state: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    const that = this;
    var object = {
      unionid: wx.getStorageSync('openid'),
      page: 1
    }
    var signs = app.sort_ASCII(object)
    wx.request({
      url: app.globalData.new_url + '/luck/luck/get_luck_list',
      data: {
        unionid: wx.getStorageSync('openid'),
        page: 1,
        sign: signs
      },
      method: 'POST',
      header: {
        'content-type': 'application/json'
      },
      success: function(res) {
        console.log(res)
        that.setData({
          record: res.data.content,
        })
        if (res.data.code == 200) {
          that.data.haveMore = true
        } else {
          that.data.haveMore = false
        }
      }
    })
  },
  // 上拉触底事件，请求记录数据
  onReachBottom: function() {
    const that = this
    let page = that.data.page;
    if (that.data.haveMore) {
      // 请求下一页数据
      page++;
      that.data.page = page
      var obj = {
        unionid: wx.getStorageSync('openid'),
        page: page
      }
      var sign = app.sort_ASCII(obj)
      wx.request({
        url: app.globalData.new_url + '/luck/luck/get_luck_list',
        data: {
          page: page,
          unionid: wx.getStorageSync('openid'),
          sign: sign
        },
        method: 'POST',
        header: {
          'Cache-Control': 'max-age=60,public', //60秒
        },
        success: function(res) {
          if (res.data.code == 500) {
            return
          }else{
            that.data.record = that.data.record.concat(res.data.content);
            that.setData({
              record: that.data.record,
            })
            if (res.data.code == 200) {
              that.data.haveMore = true
            } else {
              that.data.haveMore = false
            }
          }
        }
      })
    }
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  }

})